import json
import jsonpath

# 淘票票的json数据（地区）

import urllib.request

url = "https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1728634827306_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true"

headers = {
    # ':authority': 'dianying.taobao.com',
    # ':method': 'GET',
    # ':path': '/cityAction.json?activityId&_ksTS=1728634827306_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true',
    # ':scheme': 'https',
    'accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
    # 'accept-encoding': 'gzip, deflate, br, zstd',
    'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    'bx-v': '2.5.20',
    'cookie': 'thw=cn; t=23c0c50b61858303b509f3ae5834bbef; hng=CN%7Czh-CN%7CCNY%7C156; _uetvid=89fd15e0500b11ef8886579c5bff040a; tracknick=%5Cu6DE1%5Cu5FD8%5Cu6D45%5Cu964C%5Cu9621%5Cu964C; xlly_s=1; 3PcFlag=1728546516765; sgcookie=E100GRiV1Yb%2FzZL0U38Kz8MFF%2BRAWaCRcIk1wloU51dtQkya9vM0kSc4YKYzC78mZ5CWqAKdm3otMZBDYm7gn%2BCTHwb1NIfbfZfzYCUmFWFFPbA%3D; wk_cookie2=1a4f567957a5a3a7b32a3a17e752b279; wk_unb=UU8IOfyThKdC4Q%3D%3D; uc3=vt3=F8dD37ng4aD5omuyPgo%3D&id2=UU8IOfyThKdC4Q%3D%3D&lg2=U%2BGCWk%2F75gdr5Q%3D%3D&nk2=1uKPeijg0v6iar9v; lgc=%5Cu6DE1%5Cu5FD8%5Cu6D45%5Cu964C%5Cu9621%5Cu964C; dnk=%5Cu66FC%5Cu8BFA%5Cu5C14%5Cu96F7%5Cu8FEA%5Cu4E9A%5Cu5179; uc4=id4=0%40U22PHHaOiCOYQ9YYLOdviwiItewj&nk4=0%401FOYNoB5cuw3isOPB0C8P7FPi5LfHjU%3D; _cc_=UIHiLt3xSw%3D%3D; tfstk=g8SZZkc1glENyrqWdpK2UVsf39x9qhV7giOXntXDCCAg6PLDnBWuBCaYWs7Fi6L6s5U9oKAFsmT10tn2ntfYBIwTROB9DnV7Nnr5BOdwdYE7On2cKnCwmzRLVOB9DAl0FwqSgfUvLt0DisxH-KvvmdYMSp2ehKnMmCYmt2vktIxciCcHxKpqIVxDov2eHBADmVcJSIASYL8gFHSrAvwsCzAPIBommGqv7QyX9ppdY7T9ZOjZbckHQFRlIBP8icnv-tLVDxn2rObRMLfisSRAY9jGr_VI5Cby3T_VIlmHfGBGrEjuMqfybs8ljekmbHxp_HJhq-gJOMR1iG83F08XxgTkjwaL1EtwUsjO_xocZ965XeI4aXAA5LKH3ieouI8c4OhvKEiRDNlmuFvpLQwULze43xwdh07xkqLOJpR7BR3xkFvpLQwULq3vWHpeNReO.; cookie2=26a095aab6c661e83728aa9994a8c2f0; v=0; _tb_token_=e53eb43e7e173; tb_city=110100; tb_cityName="sbG+qQ=="; isg=BOvrvMQ_CDq2j1WWFYsiIL5Teg_VAP-CPUpq-11obSqB_Ate5dBH0sFSVjySXFd6',
    'priority': 'u=1, i',
    'referer': 'https://dianying.taobao.com/?spm=a1z21.3046609.city.1.32c0112a9hWECn&city=110100',
    'sec-ch-ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest',
}

request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode("utf-8")
content = content.split("(")[1].split(")")[0]  # 简单处理

with open("./21.taopiaopiao_city.json", "w", encoding="utf-8") as f:
    f.write(content)

obj = json.load(open("21.taopiaopiao_city.json", "r", encoding="utf-8"))
json_str = jsonpath.jsonpath(obj, "$..regionName")
print(json_str)
